using System.Configuration;
using System.Data.Common;

namespace Be.Timvw.Framework.Data
{
    public static class DbProviderFactoryHelper
    {
        public static DbConnection GetDbConnection(string connectionStringName)
        {
            return GetDbConnection(ConfigurationManager.ConnectionStrings[connectionStringName]);
        }

        public static DbConnection GetDbConnection(ConnectionStringSettings connectionStringSettings)
        {
            return GetDbConnection(connectionStringSettings.ProviderName, connectionStringSettings.ConnectionString);
        }

        public static DbConnection GetDbConnection(string providerInvariantName, string connectionString)
        {
            DbConnection connection = DbProviderFactories.GetFactory(providerInvariantName).CreateConnection();
            connection.ConnectionString = connectionString;
            return connection;
        }
    }
}